from PySide2.QtCore import Qt, QThread, Signal
from qfluentwidgets import InfoBar, InfoBarPosition
from app.common.config import VERSION
import time
import subprocess
import os
from utils import get_abs_path
import requests


GITHUB_URL = 'https://gitee.com/ZDYoung0519/awesome-zxsj/raw/master/'
TEMP_DIR = './TEMP'


class CheckUpdateThread(QThread):
    signal = Signal(bool)
    def __init__(self):
        super(CheckUpdateThread, self).__init__()

    def run(self):
        time.sleep(1)
        self.signal.emit(True)


class DownloadThread(QThread):
    progress = Signal(int)
    text = Signal(str)
    def __init__(self):
        super(DownloadThread, self).__init__()

    def run(self):
        # 从gitee仓库中获取build_files文件
        all_files = requests.get(GITHUB_URL + 'build_files')




        cmd = ['git', 'clone', GITHUB_URL, get_abs_path(TEMP_DIR)]
        p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        # 获取实时输出
        for line in iter(p.stdout.readline, b''):
            print(line.decode('utf-8').strip())
            self.text.emit(line.decode('utf-8').strip())
        self.text.emit("正在解压文件")

